import $ from '../common';
Page({
  data: {
    active:0,
    page:1,
    tip:'上滑加载更多',
    list:[]
  },
  onLoad(e) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || '',
      active:e.idx
    })
    this.reset()
  },
  onShow() {

  },
  onReachBottom() {
    this.setData({
      tip:'加载中'
    })
    this.getinfo()
  },
  onChange(e){
    this.setData({
      active:e.detail.index
    })
    this.reset()
  },
  reset(){
    this.setData({
      list:[],
      page:1,
      tip:'上滑加载更多'
    })
    this.getinfo()
  },
  getinfo(){
    const {active}=this.data
    let url='/group/orders'
    if(active==2)url='/group/refunds'
    $.get(url,{
      page:this.data.page,
      limit:20,
      zonecode:this.data.zonecode,
      status:active==1?'NOTPAY':''
    },res=>{
      if(res.orders.length<20){
        this.data.tip='已经到底了'
      }else{
        this.data.tip='上滑加载更多'
      }
      this.data.page++
      this.setData({
        page:this.data.page,
        tip:this.data.tip,
        list:[...this.data.list,...res.orders]
      })
    })
  },
  godetailorpay(e){
    const{idx,order_uuid='',item='',uuid=''}=e.currentTarget.dataset
    let id=this.data.active!=2?uuid:order_uuid
    if(idx==1){
      $.navigateTo(`/index/orderdetail?order_uuid=${id}`)
    }else{
      $.navigateTo(`/index/checkstand?order_uuid=${order_uuid}&info=${JSON.stringify(item)}`)
    }
  },
})